<template>
  <div class="bottom-share-btn-box">
    <template v-if="isSupportVer">
      <div class="share-channels-list">
        <div
          class="share-channels-item"
          v-for="(item, index) in shareChannels"
          @click="toShare(item)"
          :key="index"
        >
          <img class="icon" :src="item.icon" />
          <p>{{ item.text }}</p>
        </div>
      </div>
      <div class="save-img-btn" @click="toShare({ type: 'save' })">
        <img class="icon" src="https://ketang-pub.movtile.com/res/icon-down-1222.png" />
        保存到手机
      </div>
    </template>
    <div class="save-img-btn" @click="toShare({ type: 'save' })" v-else>分享</div>
  </div>
</template>
<script>import { Toast } from "vant";

  export default {
    props: {
      shareInfo: {
        type: Object,
        default: () => {}, // 接受对象，支持文字图片链接or保存图片
      },
      shareSize: {
        type: String,
      },
      shareType: {
        type: String,
      },
    },
    data() {
      return {
        shareChannels: [
          {
            type: 'wechat',
            text: '微信',
            icon: 'https://ketang-pub.movtile.com/res/icon-wechat-1222.png',
          },
          {
            type: 'moments',
            text: '朋友圈',
            icon: 'https://ketang-pub.movtile.com/res/icon-moments-1222.png',
          },
          {
            type: 'qq',
            text: 'QQ',
            icon: 'https://ketang-pub.movtile.com/res/icon-qq-1222.png',
          },
          {
            type: 'sina',
            text: '微博',
            icon: 'https://ketang-pub.movtile.com/res/icon-sina-1222.png',
          },
          {
            type: 'more',
            text: '更多',
            icon: 'https://ketang-pub.movtile.com/res/icon-more-1222.png',
          },
        ],
        isSupportVer: false,
      };
    },
    mounted() {
      this.$nextTick(() => {
        this.$appService
          .appInfo()
          .then((res) => {
            // 1.8.0 及以上可存本地
            const ver = res.version && res.version.replace(/[.]/g, '');
            if (ver && Number(ver) >= 180) {
              this.isSupportVer = true;
            }
          })
          .catch((err) => {
            console.log(err);
          });
      });
    },
    methods: {
      toShare(item) {
        this.$appService.share({
          channel: item.type,
          image: this.shareInfo.image,
          size:this.shareSize,
          type:this.shareType
        });
      },
    },
  };
</script>
<style lang="less" scoped>
  .bottom-share-btn-box {
    width: 100%;
    height: 17.2rem;
    background: #ffffff;
    border-radius: 0.5rem 0.5rem 0rem 0rem;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 2rem;
    box-shadow: 0rem 0rem 3rem 0rem rgba(0, 0, 0, 0.1);
    .share-channels-list {
      display: flex;
      justify-content: space-around;
      .share-channels-item {
        .icon {
          width: 3.4rem;
          height: 3.4rem;
        }
        p {
          font-size: 1rem;
          color: #111111;
          text-align: center;
          margin-top: 0.2rem;
        }
      }
    }
    .save-img-btn {
      height: 4.6rem;
      background: #f3f3f3;
      border-radius: 0.3rem;
      font-size: 1.4rem;
      font-weight: 600;
      color: #111111;
      display: flex;
      align-items: center;
      justify-content: center;
      margin: auto;
      margin-top: 3rem;
      .icon {
        display: block;
        width: 1.4rem;
        height: 1.4rem;
      }
    }
  }
</style>
